<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:s="http://jboss.com/products/seam/taglib"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:a="http://richfaces.org/a4j"
    xmlns:rich="http://richfaces.org/rich"
    template="layout/template.xhtml">

<ui:define name="body">

    <h:form id="user" styleClass="edit">    

        <rich:panel>
            <f:facet name="header">#{userHome.managed ? 'Edit' : 'Add'} User</f:facet>



            <s:decorate id="dscField" template="layout/edit.xhtml">
                <ui:define name="label">Dsc</ui:define>
                <h:inputTextarea id="dsc"
                               cols="80"
                               rows="10"
                              value="#{userHome.instance.dsc}"/>
            </s:decorate>


            <s:decorate id="emailField" template="layout/edit.xhtml">
                <ui:define name="label">Email</ui:define>
                <h:inputText id="email"
                       required="true"
                           size="64"
                      maxlength="64"
                          value="#{userHome.instance.email}">
                    <a:support event="onblur" reRender="emailField" bypassUpdates="true" ajaxSingle="true"/>
                </h:inputText>
            </s:decorate>


            <s:decorate id="firstnameField" template="layout/edit.xhtml">
                <ui:define name="label">Firstname</ui:define>
                <h:inputText id="firstname"
                           size="64"
                      maxlength="64"
                          value="#{userHome.instance.firstname}">
                    <a:support event="onblur" reRender="firstnameField" bypassUpdates="true" ajaxSingle="true"/>
                </h:inputText>
            </s:decorate>




            <s:decorate id="lastloggedinField" template="layout/edit.xhtml">
                <ui:define name="label">Lastloggedin</ui:define>
                <rich:calendar id="lastloggedin"
                       required="true"
                          value="#{userHome.instance.lastloggedin}" datePattern="MM/dd/yyyy hh:mm a"/>
            </s:decorate>


            <s:decorate id="lastnameField" template="layout/edit.xhtml">
                <ui:define name="label">Lastname</ui:define>
                <h:inputText id="lastname"
                           size="64"
                      maxlength="64"
                          value="#{userHome.instance.lastname}">
                    <a:support event="onblur" reRender="lastnameField" bypassUpdates="true" ajaxSingle="true"/>
                </h:inputText>
            </s:decorate>


            <s:decorate id="passwordField" template="layout/edit.xhtml">
                <ui:define name="label">Password</ui:define>
                <h:inputText id="password"
                       required="true"
                           size="32"
                      maxlength="32"
                          value="#{userHome.instance.password}">
                    <a:support event="onblur" reRender="passwordField" bypassUpdates="true" ajaxSingle="true"/>
                </h:inputText>
            </s:decorate>


            <s:decorate id="registeredField" template="layout/edit.xhtml">
                <ui:define name="label">Registered</ui:define>
                <rich:calendar id="registered"
                       required="true"
                          value="#{userHome.instance.registered}" datePattern="MM/dd/yyyy hh:mm a"/>
            </s:decorate>




            <s:decorate id="usernameField" template="layout/edit.xhtml">
                <ui:define name="label">Username</ui:define>
                <h:inputText id="username"
                       required="true"
                           size="32"
                      maxlength="32"
                          value="#{userHome.instance.username}">
                    <a:support event="onblur" reRender="usernameField" bypassUpdates="true" ajaxSingle="true"/>
                </h:inputText>
            </s:decorate>

            <div style="clear:both">
                <span class="required">*</span>
                required fields
            </div>

        </rich:panel>

        <div class="actionButtons">

            <h:commandButton id="save"
                          value="Save"
                         action="#{userHome.persist}"
                       disabled="#{!userHome.wired}"
                       rendered="#{!userHome.managed}"/>

            <h:commandButton id="update"
                          value="Save"
                         action="#{userHome.update}"
                       rendered="#{userHome.managed}"/>

            <h:commandButton id="delete"
                          value="Delete"
                         action="#{userHome.remove}"
                      immediate="true"
                       rendered="#{userHome.managed}"/>

            <s:button id="cancelEdit"
                   value="Cancel"
             propagation="end"
                    view="/User.xhtml"
                rendered="#{userHome.managed}"/>

            <s:button id="cancelAdd"
                   value="Cancel"
             propagation="end"
                    view="/#{empty userFrom ? 'UserList' : userFrom}.xhtml"
                rendered="#{!userHome.managed}"/>

        </div>
    </h:form>

<rich:tabPanel switchType="ajax">

    <rich:tab label="Friendships applied to me">
        <h:form styleClass="association" id="friendshipsAppliedToMeChildren">

            <h:outputText value="There are no friendshipsAppliedToMe associated with this user."
                       rendered="#{empty userHome.friendshipsAppliedToMe}"/>

            <rich:dataTable value="#{userHome.friendshipsAppliedToMe}"
                           var="_friendship"
                      rendered="#{not empty userHome.friendshipsAppliedToMe}"
                    rowClasses="rvgRowOne,rvgRowTwo"
                            id="friendshipsAppliedToMeTable">
                <rich:column sortBy="#{_friendship.id.user1}">
                    <f:facet name="header">User1</f:facet>
                    <h:outputText value="#{_friendship.id.user1}"/>
                </rich:column>
                <rich:column sortBy="#{_friendship.id.user2}">
                    <f:facet name="header">User2</f:facet>
                    <h:outputText value="#{_friendship.id.user2}"/>
                </rich:column>
                <rich:column sortBy="#{_friendship.confirmed}">
                    <f:facet name="header">Confirmed</f:facet>
                    <h:outputText value="#{_friendship.confirmed}"/>
                </rich:column>
            </rich:dataTable>

        </h:form>

        <f:subview rendered="#{userHome.managed}" id="friendshipsAppliedToMe">
        <div class="actionButtons">
            <s:button id="addfriendship"
                   value="Add friendship"
                    view="/FriendshipEdit.xhtml"
             propagation="none">
                 <f:param name="userId"
                         value="#{userHome.instance.id}"/>
                 <f:param name="friendshipFrom" value="User"/>
            </s:button>
        </div>
        </f:subview>
    </rich:tab>

    <rich:tab label="Friendships i applied">
        <h:form styleClass="association" id="friendshipsIAppliedChildren">

            <h:outputText value="There are no friendshipsIApplied associated with this user."
                       rendered="#{empty userHome.friendshipsIApplied}"/>

            <rich:dataTable value="#{userHome.friendshipsIApplied}"
                           var="_friendship"
                      rendered="#{not empty userHome.friendshipsIApplied}"
                    rowClasses="rvgRowOne,rvgRowTwo"
                            id="friendshipsIAppliedTable">
                <rich:column sortBy="#{_friendship.id.user1}">
                    <f:facet name="header">User1</f:facet>
                    <h:outputText value="#{_friendship.id.user1}"/>
                </rich:column>
                <rich:column sortBy="#{_friendship.id.user2}">
                    <f:facet name="header">User2</f:facet>
                    <h:outputText value="#{_friendship.id.user2}"/>
                </rich:column>
                <rich:column sortBy="#{_friendship.confirmed}">
                    <f:facet name="header">Confirmed</f:facet>
                    <h:outputText value="#{_friendship.confirmed}"/>
                </rich:column>
            </rich:dataTable>

        </h:form>

        <f:subview rendered="#{userHome.managed}" id="friendshipsIApplied">
        <div class="actionButtons">
            <s:button id="addfriendship"
                   value="Add friendship"
                    view="/FriendshipEdit.xhtml"
             propagation="none">
                 <f:param name="userId"
                         value="#{userHome.instance.id}"/>
                 <f:param name="friendshipFrom" value="User"/>
            </s:button>
        </div>
        </f:subview>
    </rich:tab>

    <rich:tab label="Role *" labelClass="required">
    <div class="association" id="roleParent">

        <h:outputText value="There is no role associated with this user."
                   rendered="#{userHome.instance.role == null}"/>

        <rich:dataTable var="_role"
                   value="#{userHome.instance.role}"
                rendered="#{userHome.instance.role != null}"
              rowClasses="rvgRowOne,rvgRowTwo"
                      id="roleTable">
            <h:column>
                <f:facet name="header">Id</f:facet>
                <h:outputText value="#{_role.id}"/>
            </h:column>
            <h:column>
                <f:facet name="header">Description</f:facet>
                <h:outputText value="#{_role.description}"/>
            </h:column>
            <h:column>
                <f:facet name="header">Title</f:facet>
                <h:outputText value="#{_role.title}"/>
            </h:column>
        </rich:dataTable>

        <div class="actionButtons">
            <s:button id="#{userHome.instance.role != null ? 'changeParent' : 'selectParent'}" value="#{userHome.instance.role != null ? 'Change' : 'Select'} role"
                       view="/RoleList.xhtml">
                <f:param name="from" value="UserEdit"/>
            </s:button>
        </div>

    </div>
    </rich:tab>

    <rich:tab label="Status *" labelClass="required">
    <div class="association" id="statusParent">

        <h:outputText value="There is no status associated with this user."
                   rendered="#{userHome.instance.status == null}"/>

        <rich:dataTable var="_status"
                   value="#{userHome.instance.status}"
                rendered="#{userHome.instance.status != null}"
              rowClasses="rvgRowOne,rvgRowTwo"
                      id="statusTable">
            <h:column>
                <f:facet name="header">Id</f:facet>
                <h:outputText value="#{_status.id}"/>
            </h:column>
            <h:column>
                <f:facet name="header">Dsc</f:facet>
                <h:outputText value="#{_status.dsc}"/>
            </h:column>
            <h:column>
                <f:facet name="header">Status</f:facet>
                <h:outputText value="#{_status.status}"/>
            </h:column>
        </rich:dataTable>

        <div class="actionButtons">
            <s:button id="#{userHome.instance.status != null ? 'changeParent' : 'selectParent'}" value="#{userHome.instance.status != null ? 'Change' : 'Select'} status"
                       view="/StatusList.xhtml">
                <f:param name="from" value="UserEdit"/>
            </s:button>
        </div>

    </div>
    </rich:tab>
</rich:tabPanel>
</ui:define>

</ui:composition>
